Hệ thống quản lý phòng khám trực tuyến bằng PHP

1 <?php
2
3 // Data functions (insert, update, delete, form)
for table medical_records
4
5 // This script and data application were generated
by AppGini 5.62
6 // Download AppGini
for free from https://bigprof.com/appgini/download/
7
8 function medical_records_insert(){
9     
global $Translation;
10
11     
// mm: can member insert record?
12     $arrPerm=getTablePermissions(
'medical_records');
13     
if(!$arrPerm[1]){
14         
return false;
15     }
16
17     $data[
'description'] = br2nl(makeSafe($_REQUEST['description']));
18     $data[
'image_1'] = PrepareUploadedFile('image_1', 1024000,'jpg|jpeg|gif|png', false, '');
19     
if($data['image_1']) createThumbnail($data['image_1'], getThumbnailSpecs('medical_records', 'image_1', 'tv'));
20     
if($data['image_1']) createThumbnail($data['image_1'], getThumbnailSpecs('medical_records', 'image_1', 'dv'));
21     $data[
'image_2'] = PrepareUploadedFile('image_2', 1024000,'jpg|jpeg|gif|png', false, '');
22     
if($data['image_2']) createThumbnail($data['image_2'], getThumbnailSpecs('medical_records', 'image_2', 'tv'));
23     
if($data['image_2']) createThumbnail($data['image_2'], getThumbnailSpecs('medical_records', 'image_2', 'dv'));
24     $data[
'image_3'] = PrepareUploadedFile('image_3', 1024000,'jpg|jpeg|gif|png', false, '');
25     
if($data['image_3']) createThumbnail($data['image_3'], getThumbnailSpecs('medical_records', 'image_3', 'tv'));
26     
if($data['image_3']) createThumbnail($data['image_3'], getThumbnailSpecs('medical_records', 'image_3', 'dv'));
27     $data[
'image_4'] = PrepareUploadedFile('image_4', 1024000,'jpg|jpeg|gif|png', false, '');
28     
if($data['image_4']) createThumbnail($data['image_4'], getThumbnailSpecs('medical_records', 'image_4', 'tv'));
29     
if($data['image_4']) createThumbnail($data['image_4'], getThumbnailSpecs('medical_records', 'image_4', 'dv'));
30     $data[
'image_5'] = PrepareUploadedFile('image_5', 1024000,'jpg|jpeg|gif|png', false, '');
31     
if($data['image_5']) createThumbnail($data['image_5'], getThumbnailSpecs('medical_records', 'image_5', 'tv'));
32     
if($data['image_5']) createThumbnail($data['image_5'], getThumbnailSpecs('medical_records', 'image_5', 'dv'));
33     $data[
'document_1'] = PrepareUploadedFile('document_1', 5120000,'txt|doc|docx|docm|odt|pdf|rtf', false, '');
34     $data[
'document_2'] = PrepareUploadedFile('document_2', 5120000,'txt|doc|docx|docm|odt|pdf|rtf', false, '');
35     $data[
'document_3'] = PrepareUploadedFile('document_3', 5120000,'txt|doc|docx|docm|odt|pdf|rtf', false, '');
36     $data[
'document_4'] = PrepareUploadedFile('document_4', 5120000,'txt|doc|docx|docm|odt|pdf|rtf', false, '');
37     $data[
'document_5'] = PrepareUploadedFile('document_5', 5120000,'txt|doc|docx|docm|odt|pdf|rtf', false, '');
38
39     
/* for empty upload fields, when saving a copy of an existing record, copy the original upload field */
40     
if($_REQUEST['SelectedID']){
41         $res = sql(
"select * from medical_records where id='" . makeSafe($_REQUEST['SelectedID']) . "'", $eo);
42         
if($row = db_fetch_assoc($res)){
43             
if(!$data['image_1']) $data['image_1'] = makeSafe($row['image_1']);
44             
if(!$data['image_2']) $data['image_2'] = makeSafe($row['image_2']);
45             
if(!$data['image_3']) $data['image_3'] = makeSafe($row['image_3']);
46             
if(!$data['image_4']) $data['image_4'] = makeSafe($row['image_4']);
47             
if(!$data['image_5']) $data['image_5'] = makeSafe($row['image_5']);
48             
if(!$data['document_1']) $data['document_1'] = makeSafe($row['document_1']);
49             
if(!$data['document_2']) $data['document_2'] = makeSafe($row['document_2']);
50             
if(!$data['document_3']) $data['document_3'] = makeSafe($row['document_3']);
51             
if(!$data['document_4']) $data['document_4'] = makeSafe($row['document_4']);
52             
if(!$data['document_5']) $data['document_5'] = makeSafe($row['document_5']);
53         }
54     }
55
56     
// hook: medical_records_before_insert
57     
if(function_exists('medical_records_before_insert')){
58         $args=array();
59         
if(!medical_records_before_insert($data, getMemberInfo(), $args)){ return false; }
60     }
61
62     $o = array(
'silentErrors' => true);
63     sql(
'insert into `medical_records` set ' . ($data['image_1'] != '' ? "`image_1`='{$data['image_1']}'" : '`image_1`=NULL') . ', ' . ($data['image_2'] != '' ? "`image_2`='{$data['image_2']}'" : '`image_2`=NULL') . ', ' . ($data['image_3'] != '' ? "`image_3`='{$data['image_3']}'" : '`image_3`=NULL') . ', ' . ($data['image_4'] != '' ? "`image_4`='{$data['image_4']}'" : '`image_4`=NULL') . ', ' . ($data['image_5'] != '' ? "`image_5`='{$data['image_5']}'" : '`image_5`=NULL') . ', ' . ($data['document_1'] != '' ? "`document_1`='{$data['document_1']}'" : '`document_1`=NULL') . ', ' . ($data['document_2'] != '' ? "`document_2`='{$data['document_2']}'" : '`document_2`=NULL') . ', ' . ($data['document_3'] != '' ? "`document_3`='{$data['document_3']}'" : '`document_3`=NULL') . ', ' . ($data['document_4'] != '' ? "`document_4`='{$data['document_4']}'" : '`document_4`=NULL') . ', ' . ($data['document_5'] != '' ? "`document_5`='{$data['document_5']}'" : '`document_5`=NULL') . ', `description`=' . (($data['description'] !== '' && $data['description'] !== NULL) ? "'{$data['description']}'" : 'NULL'), $o);
64     
if($o['error']!=''){
65         echo $o[
'error'];
66         echo
"<a href=\"medical_records_view.php?addNew_x=1\">{$Translation['< back']}</a>";
67         exit;
68     }
69
70     $recID = db_insert_id(db_link());
71
72     
// automatic patient
73     
if($_REQUEST['filterer_patient']){
74         sql(
"update `medical_records` set `patient`='" . makeSafe($_REQUEST['filterer_patient']) . "' where `id`='" . makeSafe($recID, false) . "'", $eo);
75     }
76
77     
// hook: medical_records_after_insert
78     
if(function_exists('medical_records_after_insert')){
79         $res = sql(
"select * from `medical_records` where `id`='" . makeSafe($recID, false) . "' limit 1", $eo);
80         
if($row = db_fetch_assoc($res)){
81             $data = array_map(
'makeSafe', $row);
82         }
83         $data[
'selectedID'] = makeSafe($recID, false);
84         $args=array();
85         
if(!medical_records_after_insert($data, getMemberInfo(), $args)){ return $recID; }
86     }
87
88     
// mm: save ownership data
89     sql(
"insert ignore into membership_userrecords set tableName='medical_records', pkValue='" . makeSafe($recID, false) . "', memberID='" . makeSafe(getLoggedMemberID(), false) . "', dateAdded='" . time() . "', dateUpdated='" . time() . "', groupID='" . getLoggedGroupID() . "'", $eo);
90
91     
return $recID;
92 }
93
94 function medical_records_delete($selected_id, $AllowDeleteOfParents=
false, $skipChecks=false){
95     
// insure referential integrity ...
96     
global $Translation;
97     $selected_id=makeSafe($selected_id);
98
99     
// mm: can member delete record?
100     $arrPerm=getTablePermissions(
'medical_records');
101     $ownerGroupID=sqlValue(
"select groupID from membership_userrecords where tableName='medical_records' and pkValue='$selected_id'");
102     $ownerMemberID=sqlValue(
"select lcase(memberID) from membership_userrecords where tableName='medical_records' and pkValue='$selected_id'");
103     
if(($arrPerm[4]==1 && $ownerMemberID==getLoggedMemberID()) || ($arrPerm[4]==2 && $ownerGroupID==getLoggedGroupID()) || $arrPerm[4]==3){ // allow delete?
104         
// delete allowed, so continue ...
105     }
else{
106         
return $Translation['You don\'t have enough permissions to delete this record'];
107     }
108
109     
// hook: medical_records_before_delete
110     
if(function_exists('medical_records_before_delete')){
111         $args=array();
112         
if(!medical_records_before_delete($selected_id, $skipChecks, getMemberInfo(), $args))
113             
return $Translation['Couldn\'t delete this record'];
114     }
115
116     sql(
"delete from `medical_records` where `id`='$selected_id'", $eo);
117
118     
// hook: medical_records_after_delete
119     
if(function_exists('medical_records_after_delete')){
120         $args=array();
121         medical_records_after_delete($selected_id, getMemberInfo(), $args);
122     }
123
124     
// mm: delete ownership data
125     sql(
"delete from membership_userrecords where tableName='medical_records' and pkValue='$selected_id'", $eo);
126 }
127
128 function medical_records_update($selected_id){
129     
global $Translation;
130
131     
// mm: can member edit record?
132     $arrPerm=getTablePermissions(
'medical_records');
133     $ownerGroupID=sqlValue(
"select groupID from membership_userrecords where tableName='medical_records' and pkValue='".makeSafe($selected_id)."'");
134     $ownerMemberID=sqlValue(
"select lcase(memberID) from membership_userrecords where tableName='medical_records' and pkValue='".makeSafe($selected_id)."'");
135     
if(($arrPerm[3]==1 && $ownerMemberID==getLoggedMemberID()) || ($arrPerm[3]==2 && $ownerGroupID==getLoggedGroupID()) || $arrPerm[3]==3){ // allow update?
136         
// update allowed, so continue ...
137     }
else{
138         
return false;
139     }
140
141     $data[
'description'] = br2nl(makeSafe($_REQUEST['description']));
142     $data[
'selectedID']=makeSafe($selected_id);
143     
if($_REQUEST['image_1_remove'] == 1){
144         $data[
'image_1'] = '';
145     }
else{
146         $data[
'image_1'] = PrepareUploadedFile('image_1', 1024000, 'jpg|jpeg|gif|png', false, "");
147         
if($data['image_1']) createThumbnail($data['image_1'], getThumbnailSpecs('medical_records', 'image_1', 'tv'));
148         
if($data['image_1']) createThumbnail($data['image_1'], getThumbnailSpecs('medical_records', 'image_1', 'dv'));
149     }
150     
if($_REQUEST['image_2_remove'] == 1){
151         $data[
'image_2'] = '';
152     }
else{
153         $data[
'image_2'] = PrepareUploadedFile('image_2', 1024000, 'jpg|jpeg|gif|png', false, "");
154         
if($data['image_2']) createThumbnail($data['image_2'], getThumbnailSpecs('medical_records', 'image_2', 'tv'));
155         
if($data['image_2']) createThumbnail($data['image_2'], getThumbnailSpecs('medical_records', 'image_2', 'dv'));
156     }
157     
if($_REQUEST['image_3_remove'] == 1){
158         $data[
'image_3'] = '';
159     }
else{
160         $data[
'image_3'] = PrepareUploadedFile('image_3', 1024000, 'jpg|jpeg|gif|png', false, "");
161         
if($data['image_3']) createThumbnail($data['image_3'], getThumbnailSpecs('medical_records', 'image_3', 'tv'));
162         
if($data['image_3']) createThumbnail($data['image_3'], getThumbnailSpecs('medical_records', 'image_3', 'dv'));
163     }
164     
if($_REQUEST['image_4_remove'] == 1){
165         $data[
'image_4'] = '';
166     }
else{
167         $data[
'image_4'] = PrepareUploadedFile('image_4', 1024000, 'jpg|jpeg|gif|png', false, "");
168         
if($data['image_4']) createThumbnail($data['image_4'], getThumbnailSpecs('medical_records', 'image_4', 'tv'));
169         
if($data['image_4']) createThumbnail($data['image_4'], getThumbnailSpecs('medical_records', 'image_4', 'dv'));
170     }
171     
if($_REQUEST['image_5_remove'] == 1){
172         $data[
'image_5'] = '';
173     }
else{
174         $data[
'image_5'] = PrepareUploadedFile('image_5', 1024000, 'jpg|jpeg|gif|png', false, "");
175         
if($data['image_5']) createThumbnail($data['image_5'], getThumbnailSpecs('medical_records', 'image_5', 'tv'));
176         
if($data['image_5']) createThumbnail($data['image_5'], getThumbnailSpecs('medical_records', 'image_5', 'dv'));
177     }
178     
if($_REQUEST['document_1_remove'] == 1){
179         $data[
'document_1'] = '';
180     }
else{
181         $data[
'document_1'] = PrepareUploadedFile('document_1', 5120000, 'txt|doc|docx|docm|odt|pdf|rtf', false, "");
182     }
183     
if($_REQUEST['document_2_remove'] == 1){
184         $data[
'document_2'] = '';
185     }
else{
186         $data[
'document_2'] = PrepareUploadedFile('document_2', 5120000, 'txt|doc|docx|docm|odt|pdf|rtf', false, "");
187     }
188     
if($_REQUEST['document_3_remove'] == 1){
189         $data[
'document_3'] = '';
190     }
else{
191         $data[
'document_3'] = PrepareUploadedFile('document_3', 5120000, 'txt|doc|docx|docm|odt|pdf|rtf', false, "");
192     }
193     
if($_REQUEST['document_4_remove'] == 1){
194         $data[
'document_4'] = '';
195     }
else{
196         $data[
'document_4'] = PrepareUploadedFile('document_4', 5120000, 'txt|doc|docx|docm|odt|pdf|rtf', false, "");
197     }
198     
if($_REQUEST['document_5_remove'] == 1){
199         $data[
'document_5'] = '';
200     }
else{
201         $data[
'document_5'] = PrepareUploadedFile('document_5', 5120000, 'txt|doc|docx|docm|odt|pdf|rtf', false, "");
202     }
203
204     
// hook: medical_records_before_update
205     
if(function_exists('medical_records_before_update')){
206         $args=array();
207         
if(!medical_records_before_update($data, getMemberInfo(), $args)){ return false; }
208     }
209
210     $o=array(
'silentErrors' => true);
211     sql(
'update `medical_records` set ' . ($data['image_1']!='' ? "`image_1`='{$data['image_1']}'" : ($_REQUEST['image_1_remove'] != 1 ? '`image_1`=`image_1`' : '`image_1`=NULL')) . ', ' . ($data['image_2']!='' ? "`image_2`='{$data['image_2']}'" : ($_REQUEST['image_2_remove'] != 1 ? '`image_2`=`image_2`' : '`image_2`=NULL')) . ', ' . ($data['image_3']!='' ? "`image_3`='{$data['image_3']}'" : ($_REQUEST['image_3_remove'] != 1 ? '`image_3`=`image_3`' : '`image_3`=NULL')) . ', ' . ($data['image_4']!='' ? "`image_4`='{$data['image_4']}'" : ($_REQUEST['image_4_remove'] != 1 ? '`image_4`=`image_4`' : '`image_4`=NULL')) . ', ' . ($data['image_5']!='' ? "`image_5`='{$data['image_5']}'" : ($_REQUEST['image_5_remove'] != 1 ? '`image_5`=`image_5`' : '`image_5`=NULL')) . ', ' . ($data['document_1']!='' ? "`document_1`='{$data['document_1']}'" : ($_REQUEST['document_1_remove'] != 1 ? '`document_1`=`document_1`' : '`document_1`=NULL')) . ', ' . ($data['document_2']!='' ? "`document_2`='{$data['document_2']}'" : ($_REQUEST['document_2_remove'] != 1 ? '`document_2`=`document_2`' : '`document_2`=NULL')) . ', ' . ($data['document_3']!='' ? "`document_3`='{$data['document_3']}'" : ($_REQUEST['document_3_remove'] != 1 ? '`document_3`=`document_3`' : '`document_3`=NULL')) . ', ' . ($data['document_4']!='' ? "`document_4`='{$data['document_4']}'" : ($_REQUEST['document_4_remove'] != 1 ? '`document_4`=`document_4`' : '`document_4`=NULL')) . ', ' . ($data['document_5']!='' ? "`document_5`='{$data['document_5']}'" : ($_REQUEST['document_5_remove'] != 1 ? '`document_5`=`document_5`' : '`document_5`=NULL')) . ', `description`=' . (($data['description'] !== '' && $data['description'] !== NULL) ? "'{$data['description']}'" : 'NULL') . " where `id`='".makeSafe($selected_id)."'", $o);
212     
if($o['error']!=''){
213         echo $o[
'error'];
214         echo
'<a href="medical_records_view.php?SelectedID='.urlencode($selected_id)."\">{$Translation['< back']}</a>";
215         exit;
216     }
217
218
219     
// hook: medical_records_after_update
220     
if(function_exists('medical_records_after_update')){
221         $res = sql(
"SELECT * FROM `medical_records` WHERE `id`='{$data['selectedID']}' LIMIT 1", $eo);
222         
if($row = db_fetch_assoc($res)){
223             $data = array_map(
'makeSafe', $row);
224         }
225         $data[
'selectedID'] = $data['id'];
226         $args = array();
227         
if(!medical_records_after_update($data, getMemberInfo(), $args)){ return; }
228     }
229
230     
// mm: update ownership data
231     sql(
"update membership_userrecords set dateUpdated='".time()."' where tableName='medical_records' and pkValue='".makeSafe($selected_id)."'", $eo);
232
233 }
234
235 function medical_records_form($selected_id =
'', $AllowUpdate = 1, $AllowInsert = 1, $AllowDelete = 1, $ShowCancel = 0, $TemplateDV = '', $TemplateDVP = ''){
236     
// function to return an editable form for a table records
237     
// and fill it with data of record whose ID is $selected_id. If $selected_id
238     
// is empty, an empty form is shown, with only an 'Add New'
239     
// button displayed.
240
241     
global $Translation;
242
243     
// mm: get table permissions
244     $arrPerm=getTablePermissions(
'medical_records');
245     
if(!$arrPerm[1] && $selected_id==''){ return ''; }
246     $AllowInsert = ($arrPerm[
1] ? true : false);
247     
// print preview?
248     $dvprint =
false;
249     
if($selected_id && $_REQUEST['dvprint_x'] != ''){
250         $dvprint =
true;
251     }
252
253     $filterer_patient = thisOr(undo_magic_quotes($_REQUEST[
'filterer_patient']), '');
254
255     
// populate filterers, starting from children to grand-parents
256
257     
// unique random identifier
258     $rnd1 = ($dvprint ? rand(
1000000, 9999999) : '');
259     
// combobox: patient
260     $combo_patient =
new DataCombo;
261
262     
if($selected_id){
263         
// mm: check member permissions
264         
if(!$arrPerm[2]){
265             
return "";
266         }
267         
// mm: who is the owner?
268         $ownerGroupID=sqlValue(
"select groupID from membership_userrecords where tableName='medical_records' and pkValue='".makeSafe($selected_id)."'");
269         $ownerMemberID=sqlValue(
"select lcase(memberID) from membership_userrecords where tableName='medical_records' and pkValue='".makeSafe($selected_id)."'");
270         
if($arrPerm[2]==1 && getLoggedMemberID()!=$ownerMemberID){
271             
return "";
272         }
273         
if($arrPerm[2]==2 && getLoggedGroupID()!=$ownerGroupID){
274             
return "";
275         }
276
277         
// can edit?
278         
if(($arrPerm[3]==1 && $ownerMemberID==getLoggedMemberID()) || ($arrPerm[3]==2 && $ownerGroupID==getLoggedGroupID()) || $arrPerm[3]==3){
279             $AllowUpdate=
1;
280         }
else{
281             $AllowUpdate=
0;
282         }
283
284         $res = sql(
"select * from `medical_records` where `id`='".makeSafe($selected_id)."'", $eo);
285         
if(!($row = db_fetch_array($res))){
286             
return error_message($Translation['No records found'], 'medical_records_view.php', false);
287         }
288         $urow = $row;
/* unsanitized data */
289         $hc =
new CI_Input();
290         $row = $hc->xss_clean($row);
/* sanitize data */
291         $combo_patient->SelectedData = $row[
'patient'];
292     }
else{
293         $combo_patient->SelectedData = $filterer_patient;
294     }
295     $combo_patient->HTML =
'<span id="patient-container' . $rnd1 . '"></span><input type="hidden" name="patient" id="patient' . $rnd1 . '" value="' . html_attr($combo_patient->SelectedData) . '">';
296     $combo_patient->MatchText =
'<span id="patient-container-readonly' . $rnd1 . '"></span><input type="hidden" name="patient" id="patient' . $rnd1 . '" value="' . html_attr($combo_patient->SelectedData) . '">';
297
298     ob_start();
299     ?>
300
301     <script>
302         
// initial lookup values
303         AppGini.current_patient__RAND__ = { text:
"", value: "<?php echo addslashes($selected_id ? $urow['patient'] : $filterer_patient); ?>"};
304
305         jQuery(function() {
306             setTimeout(function(){
307                 
if(typeof(patient_reload__RAND__) == 'function') patient_reload__RAND__();
308             },
10); /* we need to slightly delay client-side execution of the above code to allow AppGini.ajaxCache to work */
309         });
310         function patient_reload__RAND__(){
311         <?php
if(($AllowUpdate || $AllowInsert) && !$dvprint){ ?>
312
313             $j(
"#patient-container__RAND__").select2({
314                 
/* initial default value */
315                 initSelection: function(e, c){
316                     $j.ajax({
317                         url:
'ajax_combo.php',
318                         dataType:
'json',
319                         data: { id: AppGini.current_patient__RAND__.
value, t: 'medical_records', f: 'patient' },
320                         success: function(resp){
321                             c({
322                                 id: resp.results[
0].id,
323                                 text: resp.results[
0].text
324                             });
325                             $j(
'[name="patient"]').val(resp.results[0].id);
326                             $j(
'[id=patient-container-readonly__RAND__]').html('<span id="patient-match-text">' + resp.results[0].text + '</span>');
327                             
if(resp.results[0].id == '<?php echo empty_lookup_value; ?>'){ $j('.btn[id=patients_view_parent]').hide(); }else{ $j('.btn[id=patients_view_parent]').show(); }
328
329
330                             
if(typeof(patient_update_autofills__RAND__) == 'function') patient_update_autofills__RAND__();
331                         }
332                     });
333                 },
334                 width: ($j(
'fieldset .col-xs-11').width() - select2_max_width_decrement()) + 'px',
335                 formatNoMatches: function(term){
return '<?php echo addslashes($Translation['No matches found!']); ?>'; },
336                 minimumResultsForSearch:
10,
337                 loadMorePadding:
200,
338                 ajax: {
339                     url:
'ajax_combo.php',
340                     dataType:
'json',
341                     cache:
true,
342                     data: function(term, page){
return { s: term, p: page, t: 'medical_records', f: 'patient' }; },
343                     results: function(resp, page){
return resp; }
344                 },
345                 escapeMarkup: function(str){
return str; }
346             }).
on('change', function(e){
347                 AppGini.current_patient__RAND__.
value = e.added.id;
348                 AppGini.current_patient__RAND__.text = e.added.text;
349                 $j(
'[name="patient"]').val(e.added.id);
350                 
if(e.added.id == '<?php echo empty_lookup_value; ?>'){ $j('.btn[id=patients_view_parent]').hide(); }else{ $j('.btn[id=patients_view_parent]').show(); }
351
352
353                 
if(typeof(patient_update_autofills__RAND__) == 'function') patient_update_autofills__RAND__();
354             });
355
356             
if(!$j("#patient-container__RAND__").length){
357                 $j.ajax({
358                     url:
'ajax_combo.php',
359                     dataType:
'json',
360                     data: { id: AppGini.current_patient__RAND__.
value, t: 'medical_records', f: 'patient' },
361                     success: function(resp){
362                         $j(
'[name="patient"]').val(resp.results[0].id);
363                         $j(
'[id=patient-container-readonly__RAND__]').html('<span id="patient-match-text">' + resp.results[0].text + '</span>');
364                         
if(resp.results[0].id == '<?php echo empty_lookup_value; ?>'){ $j('.btn[id=patients_view_parent]').hide(); }else{ $j('.btn[id=patients_view_parent]').show(); }
365
366                         
if(typeof(patient_update_autofills__RAND__) == 'function') patient_update_autofills__RAND__();
367                     }
368                 });
369             }
370
371         <?php }
else{ ?>
372
373             $j.ajax({
374                 url:
'ajax_combo.php',
375                 dataType:
'json',
376                 data: { id: AppGini.current_patient__RAND__.
value, t: 'medical_records', f: 'patient' },
377                 success: function(resp){
378                     $j(
'[id=patient-container__RAND__], [id=patient-container-readonly__RAND__]').html('<span id="patient-match-text">' + resp.results[0].text + '</span>');
379                     
if(resp.results[0].id == '<?php echo empty_lookup_value; ?>'){ $j('.btn[id=patients_view_parent]').hide(); }else{ $j('.btn[id=patients_view_parent]').show(); }
380
381                     
if(typeof(patient_update_autofills__RAND__) == 'function') patient_update_autofills__RAND__();
382                 }
383             });
384         <?php } ?>
385
386         }
387     </script>
388     <?php
389
390     $lookups = str_replace(
'__RAND__', $rnd1, ob_get_contents());
391     ob_end_clean();
392
393
394     
// code for template based detail view forms
395
396     
// open the detail view template
397     
if($dvprint){
398         $template_file = is_file(
"./{$TemplateDVP}") ? "./{$TemplateDVP}" : './templates/medical_records_templateDVP.html';
399         $templateCode = @file_get_contents($template_file);
400     }
else{
401         $template_file = is_file(
"./{$TemplateDV}") ? "./{$TemplateDV}" : './templates/medical_records_templateDV.html';
402         $templateCode = @file_get_contents($template_file);
403     }
404
405     
// process form title
406     $templateCode = str_replace(
'<%%DETAIL_VIEW_TITLE%%>', 'Patient document details', $templateCode);
407     $templateCode = str_replace(
'<%%RND1%%>', $rnd1, $templateCode);
408     $templateCode = str_replace(
'<%%EMBEDDED%%>', ($_REQUEST['Embedded'] ? 'Embedded=1' : ''), $templateCode);
409     
// process buttons
410     
if($AllowInsert){
411         
if(!$selected_id) $templateCode=str_replace('<%%INSERT_BUTTON%%>', '<button type="submit" class="btn btn-success" id="insert" name="insert_x" value="1" onclick="return medical_records_validateData();"><i class="glyphicon glyphicon-plus-sign"></i> ' . $Translation['Save New'] . '</button>', $templateCode);
412         $templateCode=str_replace(
'<%%INSERT_BUTTON%%>', '<button type="submit" class="btn btn-default" id="insert" name="insert_x" value="1" onclick="return medical_records_validateData();"><i class="glyphicon glyphicon-plus-sign"></i> ' . $Translation['Save As Copy'] . '</button>', $templateCode);
413     }
else{
414         $templateCode=str_replace(
'<%%INSERT_BUTTON%%>', '', $templateCode);
415     }
416
417     
// 'Back' button action
418     
if($_REQUEST['Embedded']){
419         $backAction =
'window.parent.jQuery(\'.modal\').modal(\'hide\'); return false;';
420     }
else{
421         $backAction =
'$$(\'form\')[0].writeAttribute(\'novalidate\', \'novalidate\'); document.myform.reset(); return true;';
422     }
423
424     
if($selected_id){
425         
if(!$_REQUEST['Embedded']) $templateCode=str_replace('<%%DVPRINT_BUTTON%%>', '<button type="submit" class="btn btn-default" id="dvprint" name="dvprint_x" value="1" onclick="$$(\'form\')[0].writeAttribute(\'novalidate\', \'novalidate\'); document.myform.reset(); return true;" title="' . html_attr($Translation['Print Preview']) . '"><i class="glyphicon glyphicon-print"></i> ' . $Translation['Print Preview'] . '</button>', $templateCode);
426         
if($AllowUpdate){
427             $templateCode=str_replace(
'<%%UPDATE_BUTTON%%>', '<button type="submit" class="btn btn-success btn-lg" id="update" name="update_x" value="1" onclick="return medical_records_validateData();" title="' . html_attr($Translation['Save Changes']) . '"><i class="glyphicon glyphicon-ok"></i> ' . $Translation['Save Changes'] . '</button>', $templateCode);
428         }
else{
429             $templateCode=str_replace(
'<%%UPDATE_BUTTON%%>', '', $templateCode);
430         }
431         
if(($arrPerm[4]==1 && $ownerMemberID==getLoggedMemberID()) || ($arrPerm[4]==2 && $ownerGroupID==getLoggedGroupID()) || $arrPerm[4]==3){ // allow delete?
432             $templateCode=str_replace(
'<%%DELETE_BUTTON%%>', '<button type="submit" class="btn btn-danger" id="delete" name="delete_x" value="1" onclick="return confirm(\'' . $Translation['are you sure?'] . '\');" title="' . html_attr($Translation['Delete']) . '"><i class="glyphicon glyphicon-trash"></i> ' . $Translation['Delete'] . '</button>', $templateCode);
433         }
else{
434             $templateCode=str_replace(
'<%%DELETE_BUTTON%%>', '', $templateCode);
435         }
436         $templateCode=str_replace(
'<%%DESELECT_BUTTON%%>', '<button type="submit" class="btn btn-default" id="deselect" name="deselect_x" value="1" onclick="' . $backAction . '" title="' . html_attr($Translation['Back']) . '"><i class="glyphicon glyphicon-chevron-left"></i> ' . $Translation['Back'] . '</button>', $templateCode);
437     }
else{
438         $templateCode=str_replace(
'<%%UPDATE_BUTTON%%>', '', $templateCode);
439         $templateCode=str_replace(
'<%%DELETE_BUTTON%%>', '', $templateCode);
440         $templateCode=str_replace(
'<%%DESELECT_BUTTON%%>', ($ShowCancel ? '<button type="submit" class="btn btn-default" id="deselect" name="deselect_x" value="1" onclick="' . $backAction . '" title="' . html_attr($Translation['Back']) . '"><i class="glyphicon glyphicon-chevron-left"></i> ' . $Translation['Back'] . '</button>' : ''), $templateCode);
441     }
442
443     
// set records to read only if user can't insert new records and can't edit current record
444     
if(($selected_id && !$AllowUpdate && !$AllowInsert) || (!$selected_id && !$AllowInsert)){
445         $jsReadOnly .=
"\tjQuery('#image_1').replaceWith('<div class=\"form-control-static\" id=\"image_1\">' + (jQuery('#image_1').val() || '') + '</div>');\n";
446         $jsReadOnly .=
"\tjQuery('#image_2').replaceWith('<div class=\"form-control-static\" id=\"image_2\">' + (jQuery('#image_2').val() || '') + '</div>');\n";
447         $jsReadOnly .=
"\tjQuery('#image_3').replaceWith('<div class=\"form-control-static\" id=\"image_3\">' + (jQuery('#image_3').val() || '') + '</div>');\n";
448         $jsReadOnly .=
"\tjQuery('#image_4').replaceWith('<div class=\"form-control-static\" id=\"image_4\">' + (jQuery('#image_4').val() || '') + '</div>');\n";
449         $jsReadOnly .=
"\tjQuery('#image_5').replaceWith('<div class=\"form-control-static\" id=\"image_5\">' + (jQuery('#image_5').val() || '') + '</div>');\n";
450         $jsReadOnly .=
"\tjQuery('#document_1').replaceWith('<div class=\"form-control-static\" id=\"document_1\">' + (jQuery('#document_1').val() || '') + '</div>');\n";
451         $jsReadOnly .=
"\tjQuery('#document_2').replaceWith('<div class=\"form-control-static\" id=\"document_2\">' + (jQuery('#document_2').val() || '') + '</div>');\n";
452         $jsReadOnly .=
"\tjQuery('#document_3').replaceWith('<div class=\"form-control-static\" id=\"document_3\">' + (jQuery('#document_3').val() || '') + '</div>');\n";
453         $jsReadOnly .=
"\tjQuery('#document_4').replaceWith('<div class=\"form-control-static\" id=\"document_4\">' + (jQuery('#document_4').val() || '') + '</div>');\n";
454         $jsReadOnly .=
"\tjQuery('#document_5').replaceWith('<div class=\"form-control-static\" id=\"document_5\">' + (jQuery('#document_5').val() || '') + '</div>');\n";
455         $jsReadOnly .=
"\tjQuery('#description').replaceWith('<div class=\"form-control-static\" id=\"description\">' + (jQuery('#description').val() || '') + '</div>');\n";
456         $jsReadOnly .=
"\tjQuery('.select2-container').hide();\n";
457
458         $noUploads =
true;
459     }elseif($AllowInsert){
460         $jsEditable .=
"\tjQuery('form').eq(0).data('already_changed', true);"; // temporarily disable form change handler
461             $jsEditable .=
"\tjQuery('form').eq(0).data('already_changed', false);"; // re-enable form change handler
462     }
463
464     
// process combos
465     $templateCode=str_replace(
'<%%COMBO(patient)%%>', $combo_patient->HTML, $templateCode);
466     $templateCode=str_replace(
'<%%COMBOTEXT(patient)%%>', $combo_patient->MatchText, $templateCode);
467     $templateCode=str_replace(
'<%%URLCOMBOTEXT(patient)%%>', urlencode($combo_patient->MatchText), $templateCode);
468
469     
/* lookup fields array: 'lookup field name' => array('parent table name', 'lookup field caption') */
470     $lookup_fields = array(
'patient' => array('patients', 'Patient'));
471     
foreach($lookup_fields as $luf => $ptfc){
472         $pt_perm = getTablePermissions($ptfc[
0]);
473
474         
// process foreign key links
475         
if($pt_perm['view'] || $pt_perm['edit']){
476             $templateCode = str_replace(
"<%%PLINK({$luf})%%>", '<button type="button" class="btn btn-default view_parent hspacer-md" id="' . $ptfc[0] . '_view_parent" title="' . html_attr($Translation['View'] . ' ' . $ptfc[1]) . '"><i class="glyphicon glyphicon-eye-open"></i></button>', $templateCode);
477         }
478
479         
// if user has insert permission to parent table of a lookup field, put an add new button
480         
if($pt_perm['insert'] && !$_REQUEST['Embedded']){
481             $templateCode = str_replace(
"<%%ADDNEW({$ptfc[0]})%%>", '<button type="button" class="btn btn-success add_new_parent hspacer-md" id="' . $ptfc[0] . '_add_new" title="' . html_attr($Translation['Add New'] . ' ' . $ptfc[1]) . '"><i class="glyphicon glyphicon-plus-sign"></i></button>', $templateCode);
482         }
483     }
484
485     
// process images
486     $templateCode=str_replace(
'<%%UPLOADFILE(id)%%>', '', $templateCode);
487     $templateCode=str_replace(
'<%%UPLOADFILE(patient)%%>', '', $templateCode);
488     $templateCode=str_replace(
'<%%UPLOADFILE(image_1)%%>', ($noUploads ? '' : '<input type=hidden name=MAX_FILE_SIZE value=1024000>'.$Translation['upload image'].' <input type="file" name="image_1" id="image_1">'), $templateCode);
489     
if($AllowUpdate && $row['image_1']!=''){
490         $templateCode=str_replace(
'<%%REMOVEFILE(image_1)%%>', '<br><input type="checkbox" name="image_1_remove" id="image_1_remove" value="1"> <label for="image_1_remove" style="color: red; font-weight: bold;">'.$Translation['remove image'].'</label>', $templateCode);
491     }
else{
492         $templateCode=str_replace(
'<%%REMOVEFILE(image_1)%%>', '', $templateCode);
493     }
494     $templateCode=str_replace(
'<%%UPLOADFILE(image_2)%%>', ($noUploads ? '' : '<input type=hidden name=MAX_FILE_SIZE value=1024000>'.$Translation['upload image'].' <input type="file" name="image_2" id="image_2">'), $templateCode);
495     
if($AllowUpdate && $row['image_2']!=''){
496         $templateCode=str_replace(
'<%%REMOVEFILE(image_2)%%>', '<br><input type="checkbox" name="image_2_remove" id="image_2_remove" value="1"> <label for="image_2_remove" style="color: red; font-weight: bold;">'.$Translation['remove image'].'</label>', $templateCode);
497     }
else{
498         $templateCode=str_replace(
'<%%REMOVEFILE(image_2)%%>', '', $templateCode);
499     }
500     $templateCode=str_replace(
'<%%UPLOADFILE(image_3)%%>', ($noUploads ? '' : '<input type=hidden name=MAX_FILE_SIZE value=1024000>'.$Translation['upload image'].' <input type="file" name="image_3" id="image_3">'), $templateCode);
501     
if($AllowUpdate && $row['image_3']!=''){
502         $templateCode=str_replace(
'<%%REMOVEFILE(image_3)%%>', '<br><input type="checkbox" name="image_3_remove" id="image_3_remove" value="1"> <label for="image_3_remove" style="color: red; font-weight: bold;">'.$Translation['remove image'].'</label>', $templateCode);
503     }
else{
504         $templateCode=str_replace(
'<%%REMOVEFILE(image_3)%%>', '', $templateCode);
505     }
506     $templateCode=str_replace(
'<%%UPLOADFILE(image_4)%%>', ($noUploads ? '' : '<input type=hidden name=MAX_FILE_SIZE value=1024000>'.$Translation['upload image'].' <input type="file" name="image_4" id="image_4">'), $templateCode);
507     
if($AllowUpdate && $row['image_4']!=''){
508         $templateCode=str_replace(
'<%%REMOVEFILE(image_4)%%>', '<br><input type="checkbox" name="image_4_remove" id="image_4_remove" value="1"> <label for="image_4_remove" style="color: red; font-weight: bold;">'.$Translation['remove image'].'</label>', $templateCode);
509     }
else{
510         $templateCode=str_replace(
'<%%REMOVEFILE(image_4)%%>', '', $templateCode);
511     }
512     $templateCode=str_replace(
'<%%UPLOADFILE(image_5)%%>', ($noUploads ? '' : '<input type=hidden name=MAX_FILE_SIZE value=1024000>'.$Translation['upload image'].' <input type="file" name="image_5" id="image_5">'), $templateCode);
513     
if($AllowUpdate && $row['image_5']!=''){
514         $templateCode=str_replace(
'<%%REMOVEFILE(image_5)%%>', '<br><input type="checkbox" name="image_5_remove" id="image_5_remove" value="1"> <label for="image_5_remove" style="color: red; font-weight: bold;">'.$Translation['remove image'].'</label>', $templateCode);
515     }
else{
516         $templateCode=str_replace(
'<%%REMOVEFILE(image_5)%%>', '', $templateCode);
517     }
518     $templateCode=str_replace(
'<%%UPLOADFILE(document_1)%%>', ($noUploads ? '' : '<input type=hidden name=MAX_FILE_SIZE value=5120000>'.$Translation['upload image'].' <input type="file" name="document_1" id="document_1">'), $templateCode);
519     $templateCode=str_replace(
'<%%UPLOADFILE(document_2)%%>', ($noUploads ? '' : '<input type=hidden name=MAX_FILE_SIZE value=5120000>'.$Translation['upload image'].' <input type="file" name="document_2" id="document_2">'), $templateCode);
520     
if($AllowUpdate && $row['document_2']!=''){
521         $templateCode=str_replace(
'<%%REMOVEFILE(document_2)%%>', '<br><input type="checkbox" name="document_2_remove" id="document_2_remove" value="1"> <label for="document_2_remove" style="color: red; font-weight: bold;">'.$Translation['remove image'].'</label>', $templateCode);
522     }
else{
523         $templateCode=str_replace(
'<%%REMOVEFILE(document_2)%%>', '', $templateCode);
524     }
525     $templateCode=str_replace(
'<%%UPLOADFILE(document_3)%%>', ($noUploads ? '' : '<input type=hidden name=MAX_FILE_SIZE value=5120000>'.$Translation['upload image'].' <input type="file" name="document_3" id="document_3">'), $templateCode);
526     
if($AllowUpdate && $row['document_3']!=''){
527         $templateCode=str_replace(
'<%%REMOVEFILE(document_3)%%>', '<br><input type="checkbox" name="document_3_remove" id="document_3_remove" value="1"> <label for="document_3_remove" style="color: red; font-weight: bold;">'.$Translation['remove image'].'</label>', $templateCode);
528     }
else{
529         $templateCode=str_replace(
'<%%REMOVEFILE(document_3)%%>', '', $templateCode);
530     }
531     $templateCode=str_replace(
'<%%UPLOADFILE(document_4)%%>', ($noUploads ? '' : '<input type=hidden name=MAX_FILE_SIZE value=5120000>'.$Translation['upload image'].' <input type="file" name="document_4" id="document_4">'), $templateCode);
532     
if($AllowUpdate && $row['document_4']!=''){
533         $templateCode=str_replace(
'<%%REMOVEFILE(document_4)%%>', '<br><input type="checkbox" name="document_4_remove" id="document_4_remove" value="1"> <label for="document_4_remove" style="color: red; font-weight: bold;">'.$Translation['remove image'].'</label>', $templateCode);
534     }
else{
535         $templateCode=str_replace(
'<%%REMOVEFILE(document_4)%%>', '', $templateCode);
536     }
537     $templateCode=str_replace(
'<%%UPLOADFILE(document_5)%%>', ($noUploads ? '' : '<input type=hidden name=MAX_FILE_SIZE value=5120000>'.$Translation['upload image'].' <input type="file" name="document_5" id="document_5">'), $templateCode);
538     
if($AllowUpdate && $row['document_5']!=''){
539         $templateCode=str_replace(
'<%%REMOVEFILE(document_5)%%>', '<br><input type="checkbox" name="document_5_remove" id="document_5_remove" value="1"> <label for="document_5_remove" style="color: red; font-weight: bold;">'.$Translation['remove image'].'</label>', $templateCode);
540     }
else{
541         $templateCode=str_replace(
'<%%REMOVEFILE(document_5)%%>', '', $templateCode);
542     }
543     $templateCode=str_replace(
'<%%UPLOADFILE(description)%%>', '', $templateCode);
544
545     
// process values
546     
if($selected_id){
547         $templateCode=str_replace(
'<%%VALUE(id)%%>', html_attr($row['id']), $templateCode);
548         $templateCode=str_replace(
'<%%URLVALUE(id)%%>', urlencode($urow['id']), $templateCode);
549         $templateCode=str_replace(
'<%%VALUE(patient)%%>', html_attr($row['patient']), $templateCode);
550         $templateCode=str_replace(
'<%%URLVALUE(patient)%%>', urlencode($urow['patient']), $templateCode);
551         $row[
'image_1']=($row['image_1']!=''?$row['image_1']:'blank.gif');
552         $templateCode=str_replace(
'<%%VALUE(image_1)%%>', html_attr($row['image_1']), $templateCode);
553         $templateCode=str_replace(
'<%%URLVALUE(image_1)%%>', urlencode($urow['image_1']), $templateCode);
554         $row[
'image_2']=($row['image_2']!=''?$row['image_2']:'blank.gif');
555         $templateCode=str_replace(
'<%%VALUE(image_2)%%>', html_attr($row['image_2']), $templateCode);
556         $templateCode=str_replace(
'<%%URLVALUE(image_2)%%>', urlencode($urow['image_2']), $templateCode);
557         $row[
'image_3']=($row['image_3']!=''?$row['image_3']:'blank.gif');
558         $templateCode=str_replace(
'<%%VALUE(image_3)%%>', html_attr($row['image_3']), $templateCode);
559         $templateCode=str_replace(
'<%%URLVALUE(image_3)%%>', urlencode($urow['image_3']), $templateCode);
560         $row[
'image_4']=($row['image_4']!=''?$row['image_4']:'blank.gif');
561         $templateCode=str_replace(
'<%%VALUE(image_4)%%>', html_attr($row['image_4']), $templateCode);
562         $templateCode=str_replace(
'<%%URLVALUE(image_4)%%>', urlencode($urow['image_4']), $templateCode);
563         $row[
'image_5']=($row['image_5']!=''?$row['image_5']:'blank.gif');
564         $templateCode=str_replace(
'<%%VALUE(image_5)%%>', html_attr($row['image_5']), $templateCode);
565         $templateCode=str_replace(
'<%%URLVALUE(image_5)%%>', urlencode($urow['image_5']), $templateCode);
566         $templateCode=str_replace(
'<%%VALUE(document_1)%%>', html_attr($row['document_1']), $templateCode);
567         $templateCode=str_replace(
'<%%URLVALUE(document_1)%%>', urlencode($urow['document_1']), $templateCode);
568         $templateCode=str_replace(
'<%%VALUE(document_2)%%>', html_attr($row['document_2']), $templateCode);
569         $templateCode=str_replace(
'<%%URLVALUE(document_2)%%>', urlencode($urow['document_2']), $templateCode);
570         $templateCode=str_replace(
'<%%VALUE(document_3)%%>', html_attr($row['document_3']), $templateCode);
571         $templateCode=str_replace(
'<%%URLVALUE(document_3)%%>', urlencode($urow['document_3']), $templateCode);
572         $templateCode=str_replace(
'<%%VALUE(document_4)%%>', html_attr($row['document_4']), $templateCode);
573         $templateCode=str_replace(
'<%%URLVALUE(document_4)%%>', urlencode($urow['document_4']), $templateCode);
574         $templateCode=str_replace(
'<%%VALUE(document_5)%%>', html_attr($row['document_5']), $templateCode);
575         $templateCode=str_replace(
'<%%URLVALUE(document_5)%%>', urlencode($urow['document_5']), $templateCode);
576         
if($dvprint){
577             $templateCode = str_replace(
'<%%VALUE(description)%%>', nl2br(html_attr($row['description'])), $templateCode);
578         }
else{
579             $templateCode = str_replace(
'<%%VALUE(description)%%>', html_attr($row['description']), $templateCode);
580         }
581         $templateCode=str_replace(
'<%%URLVALUE(description)%%>', urlencode($urow['description']), $templateCode);
582     }
else{
583         $templateCode=str_replace(
'<%%VALUE(id)%%>', '', $templateCode);
584         $templateCode=str_replace(
'<%%URLVALUE(id)%%>', urlencode(''), $templateCode);
585         $templateCode=str_replace(
'<%%VALUE(patient)%%>', '', $templateCode);
586         $templateCode=str_replace(
'<%%URLVALUE(patient)%%>', urlencode(''), $templateCode);
587         $templateCode=str_replace(
'<%%VALUE(image_1)%%>', 'blank.gif', $templateCode);
588         $templateCode=str_replace(
'<%%VALUE(image_2)%%>', 'blank.gif', $templateCode);
589         $templateCode=str_replace(
'<%%VALUE(image_3)%%>', 'blank.gif', $templateCode);
590         $templateCode=str_replace(
'<%%VALUE(image_4)%%>', 'blank.gif', $templateCode);
591         $templateCode=str_replace(
'<%%VALUE(image_5)%%>', 'blank.gif', $templateCode);
592         $templateCode=str_replace(
'<%%VALUE(document_1)%%>', '', $templateCode);
593         $templateCode=str_replace(
'<%%URLVALUE(document_1)%%>', urlencode(''), $templateCode);
594         $templateCode=str_replace(
'<%%VALUE(document_2)%%>', '', $templateCode);
595         $templateCode=str_replace(
'<%%URLVALUE(document_2)%%>', urlencode(''), $templateCode);
596         $templateCode=str_replace(
'<%%VALUE(document_3)%%>', '', $templateCode);
597         $templateCode=str_replace(
'<%%URLVALUE(document_3)%%>', urlencode(''), $templateCode);
598         $templateCode=str_replace(
'<%%VALUE(document_4)%%>', '', $templateCode);
599         $templateCode=str_replace(
'<%%URLVALUE(document_4)%%>', urlencode(''), $templateCode);
600         $templateCode=str_replace(
'<%%VALUE(document_5)%%>', '', $templateCode);
601         $templateCode=str_replace(
'<%%URLVALUE(document_5)%%>', urlencode(''), $templateCode);
602         $templateCode=str_replace(
'<%%VALUE(description)%%>', '', $templateCode);
603         $templateCode=str_replace(
'<%%URLVALUE(description)%%>', urlencode(''), $templateCode);
604     }
605
606     
// process translations
607     
foreach($Translation as $symbol=>$trans){
608         $templateCode=str_replace(
"<%%TRANSLATION($symbol)%%>", $trans, $templateCode);
609     }
610
611     
// clear scrap
612     $templateCode=str_replace(
'<%%', '<!-- ', $templateCode);
613     $templateCode=str_replace(
'%%>', ' -->', $templateCode);
614
615     
// hide links to inaccessible tables
616     
if($_REQUEST['dvprint_x'] == ''){
617         $templateCode .=
"\n\n<script>\$j(function(){\n";
618         $arrTables = getTableList();
619         
foreach($arrTables as $name => $caption){
620             $templateCode .=
"\t\$j('#{$name}_link').removeClass('hidden');\n";
621             $templateCode .=
"\t\$j('#xs_{$name}_link').removeClass('hidden');\n";
622         }
623
624         $templateCode .= $jsReadOnly;
625         $templateCode .= $jsEditable;
626
627         
if(!$selected_id){
628         }
629
630         $templateCode.=
"\n});</script>\n";
631     }
632
633     
// ajaxed auto-fill fields
634     $templateCode .=
'<script>';
635     $templateCode .=
'$j(function() {';
636
637
638     $templateCode.=
"});";
639     $templateCode.=
"</script>";
640     $templateCode .= $lookups;
641
642     
// handle enforced parent values for read-only lookup fields
643     
if( $_REQUEST['FilterField'][1]=='2' && $_REQUEST['FilterOperator'][1]=='<=>'){
644         $templateCode.=
"\n<input type=hidden name=patient value=\"" . html_attr((get_magic_quotes_gpc() ? stripslashes($_REQUEST['FilterValue'][1]) : $_REQUEST['FilterValue'][1]))."\">\n";
645     }
646
647     
// don't include blank images in lightbox gallery
648     $templateCode = preg_replace(
'/blank.gif" data-lightbox=".*?"/', 'blank.gif"', $templateCode);
649
650     
// don't display empty email links
651     $templateCode=preg_replace(
'/<a .*?href="mailto:".*?<\/a>/', '', $templateCode);
652
653     
/* default field values */
654     $rdata = $jdata = get_defaults(
'medical_records');
655     
if($selected_id){
656         $jdata = get_joined_record(
'medical_records', $selected_id);
657         $rdata = $row;
658     }
659     $cache_data = array(
660         
'rdata' => array_map('nl2br', array_map('addslashes', $rdata)),
661         
'jdata' => array_map('nl2br', array_map('addslashes', $jdata)),
662     );
663     $templateCode .= loadView(
'medical_records-ajax-cache', $cache_data);
664
665     
// hook: medical_records_dv
666     
if(function_exists('medical_records_dv')){
667         $args=array();
668         medical_records_dv(($selected_id ? $selected_id : FALSE), getMemberInfo(), $templateCode, $args);
669     }
670
671     
return $templateCode;
672 }
673 ?>


Gõ tìm kiếm nhanh...